package Day2025_02_26;

public class LeetCode75 {
    public void sortColors(int[] nums) {
        int n = nums.length;
        int left = -1, right = n;
        for (int i = 0; i < right; ) {
            if (nums[i] == 0) {
                left++;
                swap(nums, i, left);
                i++;
            } else if (nums[i] == 2) {
                right--;
                swap(nums, i, right);
            } else {
                i++;
            }
        }
    }
    public static void swap(int[] nums, int i, int j) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }
}
